<template>
	<div class="index__ToTopBtn__src-commonComponent-ToTopBtn-" id="toTop" @click="time">
		<img src="//s1.hdslb.com/bfs/static/mult/images/ic_top.png" alt="">
	</div>
</template>

<script>
export default{
	name:'btop',
	mounted(){
		this.scrolltop(),
		this.time()
	},
	methods:{
		scrolltop(){
			window.addEventListener("scroll",()=>{
				var top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
				var img =document.querySelector("#toTop img");
				if(top>=10){
					toTop.style.display="block";
				}else{
					toTop.style.display="none";
				}
			});
		},
		time(){
			var time=null;
			time=setInterval(()=>{
					var t= document.documentElement.scrollTop || document.body.scrollTop;
					t-=100;
					if(t>0){
						window.scrollTo(0,t)
					}else{
						window.scrollTo(0,0);
						clearInterval(time)
					}
				},10)
		}
	}
}
</script>

<style>

</style>